package com.szcinda.controller;

import com.szcinda.controller.configuration.UserLoginToken;
import com.szcinda.repository.ExchangeRate;
import com.szcinda.service.rate.*;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("rate")
public class RateController {

    private final RateService rateService;

    public RateController(RateService rateService) {
        this.rateService = rateService;
    }

    @UserLoginToken
    @PostMapping("create")
    @OperationLogAnnotation(operDesc = "新增汇率", operModel = "公共汇率管理")
    public Result<String> create(@RequestBody RateCreateDto createDto) {
        rateService.createCommon(createDto);
        return Result.success();
    }

    @UserLoginToken
    @PostMapping("update")
    @OperationLogAnnotation(operDesc = "修改汇率", operModel = "公共汇率管理")
    public Result<String> update(@RequestBody RateUpdateDto updateDto) {
        rateService.update(updateDto);
        return Result.success();
    }

    @UserLoginToken
    @PostMapping("updatePersonal")
    @OperationLogAnnotation(operDesc = "修改汇率", operModel = "公共汇率管理")
    public Result<String> updatePersonal(@RequestBody ClientRateUpdateDto createDto) {
        rateService.updateClientRate(createDto);
        return Result.success();
    }

    @UserLoginToken
    @GetMapping("delete/{id}/{userId}")
    @OperationLogAnnotation(operDesc = "删除汇率", operModel = "公共汇率管理")
    public Result<String> delete(@PathVariable String id, @PathVariable String userId) {
        rateService.delete(id, userId);
        return Result.success();
    }

    @UserLoginToken
    @GetMapping("getCommon")
    public Result<List<ExchangeRate>> getCommon() {
        return Result.success(rateService.getCommon());
    }

    @GetMapping("currency")
    public Result<List<RateCurrencyDto>> getCurrency() {
        return Result.success(rateService.getCurrency());
    }

    @UserLoginToken
    @GetMapping("all")
    public Result<List<ExchangeRate>> all() {
        return Result.success(rateService.getAll());
    }
}
